<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php


class MServerRegistry extends MModel
{

    
    public static function initServerRegistry($db_data) {
        if ($db_data === null) {
            return null;
        }
        $token_info = new MUser();
        $token_info->osr_id                = $db_data["osr_id"];
        $token_info->osr_usa_id_ref	       = $db_data["osr_usa_id_ref"];
        $token_info->osr_consumer_key      = $db_data["osr_consumer_key"];
        $token_info->osr_consumer_secret   = $db_data["osr_consumer_secret"];
        $token_info->osr_enabled           = $db_data["osr_enabled"];
        $token_info->osr_status            = $db_data["osr_status"];
        $token_info->osr_requester_name    = $db_data["osr_requester_name"];
        $token_info->osr_requester_email   = $db_data["osr_requester_email"];
        $token_info->osr_callback_uri      = $db_data["osr_callback_uri"];
        $token_info->osr_application_uri   = $db_data["osr_application_uri"];
        $token_info->osr_application_title = $db_data["osr_application_title"];
        $token_info->osr_application_descr = $db_data["osr_application_descr"];
        return $token_info;
    }


    
    public function queryRegistryByKey($osr_consumer_key) {
        $db = MDbManager::getInstance();
        $sql = "select * from ".DB_PREFIX."_server_registry where osr_consumer_key =\"{$osr_consumer_key}\"";
        
        FXP::trace("queryServerRegistry:".$sql);
        $db_data = $db->selectDb($sql);

        if (empty($db_data)){
            return false;
        }

        return self::assembleServerToken($db_data[0]);
    }


    
    public function queryRegistryByID($id) {
        $db = MDbManager::getInstance();
        $sql = "select * from ".DB_PREFIX."_server_registry where osr_id ={$id}";
        $db_data = $db->selectDb($sql);

        if (empty($db_data)){
            return false;
        }

        return self::assembleServerToken($db_data[0]);
    }


    
    private function assembleServerToken($db_data){
        $this->osr_id                 = $db_data["osr_id"];
        $this->osr_id                 = $db_data["osr_id"];
        $this->osr_usa_id_ref	      = $db_data["osr_usa_id_ref"];
        $this->osr_consumer_key       = $db_data["osr_consumer_key"];
        $this->osr_consumer_secret    = $db_data["osr_consumer_secret"];
        $this->osr_enabled            = $db_data["osr_enabled"];
        $this->osr_status             = $db_data["osr_status"];
        $this->osr_requester_name     = $db_data["osr_requester_name"];
        $this->osr_requester_email    = $db_data["osr_requester_email"];
        $this->osr_callback_uri       = $db_data["osr_callback_uri"];
        $this->osr_application_uri    = $db_data["osr_application_uri"];
        $this->osr_application_title  = $db_data["osr_application_title"];
        $this->osr_application_descr  = $db_data["osr_application_descr"];
        return $this;
    }
}
?>